package com.sdau.nemt.service.volunteer.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sdau.nemt.common.base.result.R;
import com.sdau.nemt.service.volunteer.entity.BigData;
import com.sdau.nemt.service.volunteer.entity.Colleges;
import com.sdau.nemt.service.volunteer.entity.dto.*;
import com.sdau.nemt.service.volunteer.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 院校大数据表 前端控制器
 * </p>
 *
 * @author 往回
 * @since 2022-09-24
 */
@Api(tags = "院校大数据")
@RestController
@RequestMapping("/volunteer")
public class BigDataController {

    @Autowired
    private BigDataService bigDataService;
//
//    @Autowired
//    private RedisTemplate<String,String> redisTemplate;
//
//    @Autowired
//    private UserCollegesService userCollegesService;

    @Autowired
    private CollegesService collegesService;

//    @Autowired
//    private CollegesSpecializedService collegesSpecializedService;

//    @Autowired
//    private CollegesDetailService collegesDetailService;

    @ApiOperation("获取院校大数据")
    @GetMapping("big-data/{collegesId}")
    private R bigData(@ApiParam(name = "collegesId",value = "院校主键") @PathVariable String collegesId, HttpServletRequest request){
        LambdaQueryWrapper<BigData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BigData::getCollegesId,collegesId);
        BigData bigData = bigDataService.getBaseMapper().selectOne(wrapper);
        return R.ok().data("model",bigData);
    }

    @ApiOperation("柱状图显示该省份本科数量，专科数量，985数量，211数量")
    @GetMapping("map/{province}")
    private R mapProvince(@ApiParam(name = "province",value = "省份")@PathVariable String province){

        if (!province.equals("新疆")&&!province.equals("内蒙古")
                &&!province.equals("西藏")&&!province.equals("广西")&&!province.equals("宁夏")){
            province = province.substring(0,province.length() - 1);
        }

        LambdaQueryWrapper<Colleges> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Colleges::getProvince,province);
        Integer total = collegesService.getBaseMapper().selectCount(wrapper);
        List<Colleges> collegesList = collegesService.getBaseMapper().selectList(wrapper);
        LambdaQueryWrapper<Colleges> wrapper2 = new LambdaQueryWrapper<>();
        wrapper2.eq(Colleges::getProvince,province);
        wrapper2.eq(Colleges::getType,0);
        Integer benke = collegesService.getBaseMapper().selectCount(wrapper2);
        List<Colleges> benkeList = collegesService.getBaseMapper().selectList(wrapper2);
        LambdaQueryWrapper<Colleges> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.eq(Colleges::getProvince,province);
        wrapper3.eq(Colleges::getType,1);
        Integer zhuanke = collegesService.getBaseMapper().selectCount(wrapper3);
        List<Colleges> zhuankeList = collegesService.getBaseMapper().selectList(wrapper3);
        LambdaQueryWrapper<Colleges> wrapper4 = new LambdaQueryWrapper<>();
        wrapper4.eq(Colleges::getProvince,province);
        wrapper4.eq(Colleges::getWorldClass,0);
        Integer worldClass = collegesService.getBaseMapper().selectCount(wrapper4);
        List<Colleges> worldClassList = collegesService.getBaseMapper().selectList(wrapper4);
        LambdaQueryWrapper<Colleges> wrapper5 = new LambdaQueryWrapper<>();
        wrapper5.eq(Colleges::getProvince,province);
        wrapper5.eq(Colleges::getInnovation,0);
        Integer innovation = collegesService.getBaseMapper().selectCount(wrapper5);
        List<Colleges> innovationList = collegesService.getBaseMapper().selectList(wrapper5);

        List<CityMapDTO> cityMapDTOList = new ArrayList<>();
        for (int i = 0; i < collegesList.size(); i++) {
            if (cityMapDTOList.size()!=0) {
                int flag = 0;
                for (int j = 0; j < cityMapDTOList.size(); j++) {
                    if (cityMapDTOList.get(j).getName().equals(collegesList.get(i).getCity())) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 1) {
                    for (int j = 0; j < cityMapDTOList.size(); j++) {
                        if (cityMapDTOList.get(j).getName().equals(collegesList.get(i).getCity())) {
                            CityCollegesDTO cityCollegesDTO = new CityCollegesDTO(collegesList.get(i).getName());
                            cityMapDTOList.get(j).getCityCollegesDTOList().add(cityCollegesDTO);
                        }
                    }
                }else {
                    List<CityCollegesDTO> cityCollegesDTOList = new ArrayList<>();
                    CityCollegesDTO cityCollegesDTO = new CityCollegesDTO(collegesList.get(i).getName());
                    cityCollegesDTOList.add(cityCollegesDTO);
                    CityMapDTO cityMapDTO = new CityMapDTO();
                    cityMapDTO.setName(collegesList.get(i).getCity());
                    cityMapDTO.setCityCollegesDTOList(cityCollegesDTOList);
                    cityMapDTOList.add(cityMapDTO);
                }
            }else {
                List<CityCollegesDTO> cityCollegesDTOList = new ArrayList<>();
                CityCollegesDTO cityCollegesDTO = new CityCollegesDTO(collegesList.get(i).getName());
                cityCollegesDTOList.add(cityCollegesDTO);
                CityMapDTO cityMapDTO = new CityMapDTO();
                cityMapDTO.setName(collegesList.get(i).getCity());
                cityMapDTO.setCityCollegesDTOList(cityCollegesDTOList);
                cityMapDTOList.add(cityMapDTO);
            }

        }

        for (int i = 0; i < cityMapDTOList.size(); i++) {
            cityMapDTOList.get(i).setValue(cityMapDTOList.get(i).getCityCollegesDTOList().size());
        }


        ProvinceMapDTO provinceMapDTO = new ProvinceMapDTO(total,benke,benkeList,zhuanke,zhuankeList,
                worldClass,worldClassList,innovation,innovationList,cityMapDTOList);
        return R.ok().data("model",provinceMapDTO);

    }

    @ApiOperation("三项毕业去向落实率前六高校")
    @GetMapping("graduate")
    private R getGraduate(){
        LambdaQueryWrapper<BigData> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(BigData::getEmploymentRating);
        List<BigData> bigDataOne = bigDataService.getBaseMapper().selectList(wrapper);
        List<GraduateDTO> oneList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Colleges colleges = collegesService.getBaseMapper().selectById(bigDataOne.get(i).getId());
            GraduateDTO graduateDTO = new GraduateDTO(colleges.getName(),bigDataOne.get(i).getEmploymentRating());
            oneList.add(graduateDTO);
        }
        LambdaQueryWrapper<BigData> wrapper2 = new LambdaQueryWrapper<>();
        wrapper2.orderByDesc(BigData::getProgressionRate);
        List<BigData> bigDataTwo = bigDataService.getBaseMapper().selectList(wrapper2);
        List<GraduateDTO> twoList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Colleges colleges = collegesService.getBaseMapper().selectById(bigDataTwo.get(i).getId());
            GraduateDTO graduateDTO = new GraduateDTO(colleges.getName(),bigDataTwo.get(i).getProgressionRate());
            twoList.add(graduateDTO);
        }
        LambdaQueryWrapper<BigData> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.orderByDesc(BigData::getDepartureRate);
        List<BigData> bigDataThree = bigDataService.getBaseMapper().selectList(wrapper3);
        List<GraduateDTO> threeList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Colleges colleges = collegesService.getBaseMapper().selectById(bigDataThree.get(i).getId());
            GraduateDTO graduateDTO = new GraduateDTO(colleges.getName(),bigDataThree.get(i).getDepartureRate());
            threeList.add(graduateDTO);
        }
        return R.ok().data("oneList",oneList).data("twoList",twoList).data("threeList",threeList);

    }

    @ApiOperation("地图展示省份高校数量")
    @GetMapping("map-distribution")
    private R mapDistribution(){
        List<CollegesMapDTO> list = new ArrayList<>();
//        LambdaQueryWrapper<Colleges> wrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<Colleges> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.eq(Colleges::getProvince,"北京");
        Integer beijing = collegesService.getBaseMapper().selectCount(wrapper1);
        CollegesMapDTO collegesMapDTO1 = new CollegesMapDTO("北京",beijing);
        list.add(collegesMapDTO1);

        LambdaQueryWrapper<Colleges> wrapper2 = new LambdaQueryWrapper<>();
        wrapper2.eq(Colleges::getProvince,"上海");
        Integer shanghai = collegesService.getBaseMapper().selectCount(wrapper2);
        CollegesMapDTO collegesMapDTO2 = new CollegesMapDTO("上海",shanghai);
        list.add(collegesMapDTO2);

        LambdaQueryWrapper<Colleges> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.eq(Colleges::getProvince,"天津");
        Integer tianjin = collegesService.getBaseMapper().selectCount(wrapper3);
        CollegesMapDTO collegesMapDTO3 = new CollegesMapDTO("天津",tianjin);
        list.add(collegesMapDTO3);

        LambdaQueryWrapper<Colleges> wrapper4 = new LambdaQueryWrapper<>();
        wrapper4.eq(Colleges::getProvince,"河北");
        Integer hebei = collegesService.getBaseMapper().selectCount(wrapper4);
        CollegesMapDTO collegesMapDTO4 = new CollegesMapDTO("河北",hebei);
        list.add(collegesMapDTO4);

        LambdaQueryWrapper<Colleges> wrapper5 = new LambdaQueryWrapper<>();
        wrapper5.eq(Colleges::getProvince,"山西");
        Integer shanxi = collegesService.getBaseMapper().selectCount(wrapper5);
        CollegesMapDTO collegesMapDTO5 = new CollegesMapDTO("山西",shanxi);
        list.add(collegesMapDTO5);

        LambdaQueryWrapper<Colleges> wrapper6 = new LambdaQueryWrapper<>();
        wrapper6.eq(Colleges::getProvince,"内蒙古");
        Integer neimenggu = collegesService.getBaseMapper().selectCount(wrapper6);
        CollegesMapDTO collegesMapDTO6 = new CollegesMapDTO("内蒙古",neimenggu);
        list.add(collegesMapDTO6);

        LambdaQueryWrapper<Colleges> wrapper7 = new LambdaQueryWrapper<>();
        wrapper7.eq(Colleges::getProvince,"辽宁");
        Integer liaoning = collegesService.getBaseMapper().selectCount(wrapper7);
        CollegesMapDTO collegesMapDTO7 = new CollegesMapDTO("辽宁",liaoning);
        list.add(collegesMapDTO7);

        LambdaQueryWrapper<Colleges> wrapper8 = new LambdaQueryWrapper<>();
        wrapper8.eq(Colleges::getProvince,"吉林");
        Integer jilin = collegesService.getBaseMapper().selectCount(wrapper8);
        CollegesMapDTO collegesMapDTO8 = new CollegesMapDTO("吉林",jilin);
        list.add(collegesMapDTO8);

        LambdaQueryWrapper<Colleges> wrapper9 = new LambdaQueryWrapper<>();
        wrapper9.eq(Colleges::getProvince,"黑龙江");
        Integer heilongjiang = collegesService.getBaseMapper().selectCount(wrapper9);
        CollegesMapDTO collegesMapDTO9 = new CollegesMapDTO("黑龙江",heilongjiang);
        list.add(collegesMapDTO9);

        LambdaQueryWrapper<Colleges> wrapper10 = new LambdaQueryWrapper<>();
        wrapper10.eq(Colleges::getProvince,"江苏");
        Integer jiangsu = collegesService.getBaseMapper().selectCount(wrapper10);
        CollegesMapDTO collegesMapDTO10 = new CollegesMapDTO("江苏",jiangsu);
        list.add(collegesMapDTO10);

        LambdaQueryWrapper<Colleges> wrapper11 = new LambdaQueryWrapper<>();
        wrapper11.eq(Colleges::getProvince,"浙江");
        Integer zhejiang = collegesService.getBaseMapper().selectCount(wrapper11);
        CollegesMapDTO collegesMapDTO11 = new CollegesMapDTO("浙江",zhejiang);
        list.add(collegesMapDTO11);

        LambdaQueryWrapper<Colleges> wrapper12 = new LambdaQueryWrapper<>();
        wrapper12.eq(Colleges::getProvince,"安徽");
        Integer anhui = collegesService.getBaseMapper().selectCount(wrapper12);
        CollegesMapDTO collegesMapDTO12 = new CollegesMapDTO("安徽",anhui);
        list.add(collegesMapDTO12);

        LambdaQueryWrapper<Colleges> wrapper13 = new LambdaQueryWrapper<>();
        wrapper13.eq(Colleges::getProvince,"福建");
        Integer fujian = collegesService.getBaseMapper().selectCount(wrapper13);
        CollegesMapDTO collegesMapDTO13 = new CollegesMapDTO("福建",fujian);
        list.add(collegesMapDTO13);

        LambdaQueryWrapper<Colleges> wrapper14 = new LambdaQueryWrapper<>();
        wrapper14.eq(Colleges::getProvince,"江西");
        Integer jiangxi = collegesService.getBaseMapper().selectCount(wrapper14);
        CollegesMapDTO collegesMapDTO14 = new CollegesMapDTO("江西",jiangxi);
        list.add(collegesMapDTO14);

        LambdaQueryWrapper<Colleges> wrapper15 = new LambdaQueryWrapper<>();
        wrapper15.eq(Colleges::getProvince,"山东");
        Integer shandong = collegesService.getBaseMapper().selectCount(wrapper15);
        CollegesMapDTO collegesMapDTO15 = new CollegesMapDTO("山东",shandong);
        list.add(collegesMapDTO15);

        LambdaQueryWrapper<Colleges> wrapper16 = new LambdaQueryWrapper<>();
        wrapper16.eq(Colleges::getProvince,"河南");
        Integer henan = collegesService.getBaseMapper().selectCount(wrapper16);
        CollegesMapDTO collegesMapDTO16 = new CollegesMapDTO("河南",henan);
        list.add(collegesMapDTO16);

        LambdaQueryWrapper<Colleges> wrapper17 = new LambdaQueryWrapper<>();
        wrapper17.eq(Colleges::getProvince,"湖北");
        Integer hubei = collegesService.getBaseMapper().selectCount(wrapper17);
        CollegesMapDTO collegesMapDTO17 = new CollegesMapDTO("湖北",hubei);
        list.add(collegesMapDTO17);

        LambdaQueryWrapper<Colleges> wrapper18 = new LambdaQueryWrapper<>();
        wrapper18.eq(Colleges::getProvince,"湖南");
        Integer hunan = collegesService.getBaseMapper().selectCount(wrapper18);
        CollegesMapDTO collegesMapDTO18 = new CollegesMapDTO("湖南",hunan);
        list.add(collegesMapDTO18);

        LambdaQueryWrapper<Colleges> wrapper19 = new LambdaQueryWrapper<>();
        wrapper19.eq(Colleges::getProvince,"重庆");
        Integer chongqing = collegesService.getBaseMapper().selectCount(wrapper19);
        CollegesMapDTO collegesMapDTO19 = new CollegesMapDTO("重庆",chongqing);
        list.add(collegesMapDTO19);

        LambdaQueryWrapper<Colleges> wrapper20 = new LambdaQueryWrapper<>();
        wrapper20.eq(Colleges::getProvince,"四川");
        Integer sichuan = collegesService.getBaseMapper().selectCount(wrapper20);
        CollegesMapDTO collegesMapDTO20 = new CollegesMapDTO("四川",sichuan);
        list.add(collegesMapDTO20);

        LambdaQueryWrapper<Colleges> wrapper21 = new LambdaQueryWrapper<>();
        wrapper21.eq(Colleges::getProvince,"贵州");
        Integer guizhou = collegesService.getBaseMapper().selectCount(wrapper21);
        CollegesMapDTO collegesMapDTO21 = new CollegesMapDTO("贵州",guizhou);
        list.add(collegesMapDTO21);

        LambdaQueryWrapper<Colleges> wrapper22 = new LambdaQueryWrapper<>();
        wrapper22.eq(Colleges::getProvince,"云南");
        Integer yunnan = collegesService.getBaseMapper().selectCount(wrapper22);
        CollegesMapDTO collegesMapDTO22= new CollegesMapDTO("云南",yunnan);
        list.add(collegesMapDTO22);

        LambdaQueryWrapper<Colleges> wrapper23 = new LambdaQueryWrapper<>();
        wrapper23.eq(Colleges::getProvince,"西藏");
        Integer xizang = collegesService.getBaseMapper().selectCount(wrapper23);
        CollegesMapDTO collegesMapDTO23= new CollegesMapDTO("西藏",xizang);
        list.add(collegesMapDTO23);

        LambdaQueryWrapper<Colleges> wrapper24 = new LambdaQueryWrapper<>();
        wrapper24.eq(Colleges::getProvince,"陕西");
        Integer shanxitwo = collegesService.getBaseMapper().selectCount(wrapper24);
        CollegesMapDTO collegesMapDTO24= new CollegesMapDTO("陕西",shanxitwo);
        list.add(collegesMapDTO24);

        LambdaQueryWrapper<Colleges> wrapper25 = new LambdaQueryWrapper<>();
        wrapper25.eq(Colleges::getProvince,"甘肃");
        Integer gansu = collegesService.getBaseMapper().selectCount(wrapper25);
        CollegesMapDTO collegesMapDTO25= new CollegesMapDTO("甘肃",gansu);
        list.add(collegesMapDTO25);

        LambdaQueryWrapper<Colleges> wrapper26 = new LambdaQueryWrapper<>();
        wrapper26.eq(Colleges::getProvince,"青海");
        Integer qinghai = collegesService.getBaseMapper().selectCount(wrapper26);
        CollegesMapDTO collegesMapDTO26= new CollegesMapDTO("青海",qinghai);
        list.add(collegesMapDTO26);

        LambdaQueryWrapper<Colleges> wrapper27 = new LambdaQueryWrapper<>();
        wrapper27.eq(Colleges::getProvince,"宁夏");
        Integer ningxia = collegesService.getBaseMapper().selectCount(wrapper27);
        CollegesMapDTO collegesMapDTO27= new CollegesMapDTO("宁夏",ningxia);
        list.add(collegesMapDTO27);

        LambdaQueryWrapper<Colleges> wrapper28 = new LambdaQueryWrapper<>();
        wrapper28.eq(Colleges::getProvince,"新疆");
        Integer xinjiang = collegesService.getBaseMapper().selectCount(wrapper28);
        CollegesMapDTO collegesMapDTO28 = new CollegesMapDTO("新疆",xinjiang);
        list.add(collegesMapDTO28);

        LambdaQueryWrapper<Colleges> wrapper29 = new LambdaQueryWrapper<>();
        wrapper29.eq(Colleges::getProvince,"广东");
        Integer guangdong = collegesService.getBaseMapper().selectCount(wrapper29);
        CollegesMapDTO collegesMapDTO29 = new CollegesMapDTO("广东",guangdong);
        list.add(collegesMapDTO29);

        LambdaQueryWrapper<Colleges> wrapper30 = new LambdaQueryWrapper<>();
        wrapper30.eq(Colleges::getProvince,"广西");
        Integer guangxi = collegesService.getBaseMapper().selectCount(wrapper30);
        CollegesMapDTO collegesMapDTO30 = new CollegesMapDTO("广西",guangxi);
        list.add(collegesMapDTO30);

        LambdaQueryWrapper<Colleges> wrapper31 = new LambdaQueryWrapper<>();
        wrapper31.eq(Colleges::getProvince,"海南");
        Integer hainan = collegesService.getBaseMapper().selectCount(wrapper31);
        CollegesMapDTO collegesMapDTO31 = new CollegesMapDTO("海南",hainan);
        list.add(collegesMapDTO31);

        LambdaQueryWrapper<Colleges> wrapper32 = new LambdaQueryWrapper<>();
        wrapper32.eq(Colleges::getProvince,"香港");
        Integer xianggang = collegesService.getBaseMapper().selectCount(wrapper32);
        CollegesMapDTO collegesMapDTO32 = new CollegesMapDTO("香港",xianggang);
        list.add(collegesMapDTO32);

        LambdaQueryWrapper<Colleges> wrapper33 = new LambdaQueryWrapper<>();
        wrapper33.eq(Colleges::getProvince,"澳门");
        Integer aomen = collegesService.getBaseMapper().selectCount(wrapper33);
        CollegesMapDTO collegesMapDTO33 = new CollegesMapDTO("澳门",aomen);
        list.add(collegesMapDTO33);

        LambdaQueryWrapper<Colleges> wrapper34 = new LambdaQueryWrapper<>();
        wrapper34.eq(Colleges::getProvince,"台湾");
        Integer taiwan = collegesService.getBaseMapper().selectCount(wrapper34);
        CollegesMapDTO collegesMapDTO34 = new CollegesMapDTO("台湾",taiwan);
        list.add(collegesMapDTO34);

        return R.ok().data("pageList",list);
    }

}

